#include "mainwindow.h"
#include "ui_mainwindow.h"

#include "common/basic/MyException.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
	ui->setupUi(this);

	ui->widget->setContainers(ui->lineEditK,ui->lineEditL,ui->lineEditM,ui->lineEditN);
	ui->widget->setConsole(ui->consoleOutput);
	ui->widget->setClearButton(ui->pushButtonClear);
	ui->widget->setTables(ui->tableViewConstrains,ui->tableViewPrimitives,ui->tableViewParameters);

	//ACTIONS DELETE
	ui->tableViewPrimitives->addAction(ui->actionPrimDELETE);
	ui->tableViewConstrains->addAction(ui->actionConsDELETE);

	connect(ui->actionPrimDELETE,SIGNAL(triggered()),ui->widget,SLOT(deletePrimitive()));
	connect(ui->actionConsDELETE,SIGNAL(triggered()),ui->widget,SLOT(deleteConstraint()));

	ui->tableViewPrimitives->horizontalHeader() ->setStretchLastSection(true);
	ui->tableViewConstrains->horizontalHeader() ->setStretchLastSection(true);
	ui->tableViewParameters->horizontalHeader() ->setStretchLastSection(true);
	ui->tableViewPrimitives->setColumnWidth(0,30);
	ui->tableViewConstrains->setColumnWidth(0,30);
	ui->tableViewParameters->setColumnWidth(0,30);

	/** ten widget to nasz SkView*/
	ui->widget->setSceneRect(-400,-400,1200,800);

	// CONNECT SIGNAL - SLOT
	connect(ui->actionLINE,SIGNAL(triggered()),ui->widget,SLOT(drawLine()));
	connect(ui->actionSEGMENT,SIGNAL(triggered()),ui->widget,SLOT(drawSegment()));
	connect(ui->actionCIRCLE,SIGNAL(triggered()),ui->widget,SLOT(drawCircle()));

	//CONSTRAINT
	connect(ui->actionCONNECT_POINTS,SIGNAL(triggered()),ui->widget,SLOT(addConstraint()));
	connect(ui->actionFIX_POINT,SIGNAL(triggered()),ui->widget,SLOT(addConstraint()));
	connect(ui->actionVERTICAL,SIGNAL(triggered()),ui->widget,SLOT(addConstraint()));
	connect(ui->actionHORIZONTAL,SIGNAL(triggered()),ui->widget,SLOT(addConstraint()));
	connect(ui->actionPERPENDICULAR,SIGNAL(triggered()),ui->widget,SLOT(addConstraint()));
	connect(ui->actionPARALLEL,SIGNAL(triggered()),ui->widget,SLOT(addConstraint()));
	connect(ui->actionTANGENCY,SIGNAL(triggered()),ui->widget,SLOT(addConstraint()));
	connect(ui->actionDISTANCE,SIGNAL(triggered()),ui->widget,SLOT(addConstraint()));
	connect(ui->actionANGLE,SIGNAL(triggered()),ui->widget,SLOT(addConstraint()));
	connect(ui->actionSAME_LENGTH,SIGNAL(triggered()),ui->widget,SLOT(addConstraint()));

	connect(ui->actionSOLVE,SIGNAL(triggered()),ui->widget,SLOT(solve()));
	connect(ui->actionRELAX,SIGNAL(triggered()),ui->widget,SLOT(relax()));

}


MainWindow::~MainWindow()
{
	delete ui;

}
